package com.piggy.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.sys.api.vo.BaseAddressVo;
import com.piggy.sys.domain.vo.AddressTreeVo;
import com.piggy.sys.domain.vo.AddressVo;
import com.piggy.sys.domain.vo.CityAddressVo;
import com.piggy.sys.service.base.IBaseCityService;
import com.piggy.sys.service.base.IBaseDistrictService;
import com.piggy.sys.service.base.IBaseProvinceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Map;

/**
 * 基础地址 控制器
 *
 * @author ruoyi
 */
@Api(value = "基础地址控制器", tags = {"基础地址控制器"})
@RestController
@RequestMapping("base/address")
public class BaseAddressController extends BaseController {

    @Resource
    private IBaseProvinceService iBaseProvinceService;

    @Resource
    private IBaseCityService iBaseCityService;

    @Resource
    private IBaseDistrictService iBaseDistrictService;

    @ApiOperation("获取省集合")
    @GetMapping("getProvince")
    public R<List<BaseAddressVo>> getProvince(String parentId) {
        return R.ok(iBaseProvinceService.getProvince());
    }

    @ApiOperation("获取市集合")
    @GetMapping("getCity")
    public R<List<BaseAddressVo>> getCity(@NotEmpty(message = "省ID不能为空") String parentId) {
        return R.ok(iBaseCityService.getCity(parentId));
    }

    @ApiOperation("获取区县集合")
    @GetMapping("getDistrict")
    public R<List<BaseAddressVo>> getDistrict(@NotEmpty(message = "市ID不能为空") String parentId) {
        return R.ok(iBaseDistrictService.getDistrict(parentId));
    }

    @ApiOperation("获取所有地址集合")
    @GetMapping("getAllInfo")
    public R<List<AddressVo>> getAllInfo() {
        return R.ok(iBaseProvinceService.getAllInfo());
    }

    @ApiOperation("获取所有市集合")
    @GetMapping("getAllCityInfo")
    public R<List<CityAddressVo>> getAllCityInfo() {
        return R.ok(iBaseCityService.getAllCityInfo());
    }

    @ApiOperation("获取单个区县信息")
    @GetMapping("getDistrictInfo/{districtId}")
    public R<BaseAddressVo> getDistrictInfo(@PathVariable("districtId") String districtId) {
        return R.ok(iBaseDistrictService.getDistrictVo(districtId));
    }

    @ApiOperation("批量获取区县信息")
    @GetMapping("getDistrictMap")
    public R<Map<String, String>> getDistrictMap(@RequestParam("districtIds") List<String> districtIds) {
        return R.ok(iBaseDistrictService.getDistrictMap(districtIds));
    }

    @ApiOperation("获取所有地址集合(树形结构)")
    @GetMapping("getAllInfoTree")
    public R<List<AddressTreeVo>> getAllInfoTree() {
        return R.ok(iBaseProvinceService.getAllInfoTree());
    }

}
